package bueu.bexl;

import java.util.ArrayList;

import static bueu.bexl.utils.TypeUtils.numberValue;

public class SustractExpr extends BinayExpr {
	
	public SustractExpr(final BexlExpr expr1, final BexlExpr expr2) {
		super(expr1, expr2);
	}

	@Override
	protected final Object evaluate(Object value1, Object value2) {
		if (value1 == null) {
			return null;
		}

		if (isArray(value1)) {
			final ArrayList<Object> list = new ArrayList<Object>();
			final Object[] array = toArray(value1);
			final int length = array.length;
			
			for (int i = 0; i < length; i++) {
				Object item = array[i];

				if (!in(item, value2)) {
					list.add(item);
				}
			}

			return list.toArray();
		}

		return numberValue(value1) - numberValue(value2);
	}
	
	@Override
	public final String toString() {
		return toString("-");
	}
}
